$(document).ready(function(){
	var ChannelId=getItems("Channel") != null ? getItems("Channel") : "mychannel";
	var FabricFlag=getItems("networkName");
	var Token=getItems("token");
	var orgId=getItems("orgId");

	if(loginToken){
		$(".Reminder").hide();
		var queryInstalledUrl = '/api/block/public/queryInstalledChainCodes';
		var queryInstalledData = {
			"RequestType": "QueryInstalledChainCodesReq",
			"ChannelId":ChannelId,
			"FabricFlag":FabricFlag,
			"OrgId":orgId
		};
		$(".cover").show();
		requestPost(queryInstalledUrl, queryInstalledData,0);
	}else{
		$(".Reminder").show();
		var queryInstalledUrl = '/api/block/cache/queryInstalledChainCodes';
		var queryInstalledData = {
			"RequestType": "QueryInstalledChainCodesReq",
			"ChannelId":ChannelId,
			"FabricFlag":FabricFlag
		};
		$(".cover").show();
		requestPost(queryInstalledUrl, queryInstalledData,0);
	}

	

	function requestPost(url, Data) {
		var oData = Data;
		$.ajax({
			type: "POST",
			contentType: "application/json",
			url: url,
			data: JSON.stringify(oData),
			headers:{
				Authorization:Token,
			},
			dataType: "json",
			success: function(data) {
				$(".cover").hide();
				if(data.code==200){
					var oData=data.data;
					if(data.status==40101){
						$(".containerBox").html('<div class="NoData">登录已失效，请重新登录！</div>');
						$(".NoData").show();
						$(".NoData").css({
							marginTop:30
						})
					}
					else if(oData.total==0){
						$(".containerBox").html('<div class="NoData">暂无数据</div>');
						$(".NoData").show();
						$(".NoData").css({
							marginTop:30
						})
					}
					else{
						var str='';
						for(var i=0;i<oData.rows.length;i++){
							str += '<div class="row IntelligenceListCt"><div class="col-xs-3"><span>'+oData.rows[i].ChainCodeName+'</span></div><div class="col-xs-1"><span>'+oData.rows[i].ChainCodeVersion+'</span></div><div class="col-xs-6"><span>'+oData.rows[i].ChainCodePath+'</span></div><div class="col-xs-2 text-center"><span></span></div></div>'
						}
					
						$(".IntelligenceList").append(str);
					}	
				}else{
					$(".containerBox").html('<div class="NoData">暂无数据</div>');
					$(".NoData").show();
					$(".NoData").css({
						marginTop:30
					})
				}
				
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$(".cover").hide();
				$(".containerBox").html('<div class="NoData">暂无数据</div>');
				$(".NoData").show();
				$(".NoData").css({
					marginTop:30
				})
				console.log("调取sns接口出错");
				console.log(XMLHttpRequest.status);
				console.log(XMLHttpRequest.readyState);
				console.log(textStatus);
			}
		});
	}


})
